package com.example.yls.demoa;

import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;
import android.util.Log;

/**
 * Created by yls on 2018/11/20.
 */

public class MySqLiteOpenHelper extends SQLiteOpenHelper{
    public MySqLiteOpenHelper(Context context, String name, SQLiteDatabase.CursorFactory factory, int version) {
        super(context, name, factory, version);
    }

    @Override
    public void onCreate(SQLiteDatabase sqLiteDatabase) {
        Log.e("MySqLiteOpenHelper","onCreate");
        String sql = "create table student(stuno vachar(20), name vachar(20), age int)";
        sqLiteDatabase.execSQL(sql);
    }

    @Override
    public void onUpgrade(SQLiteDatabase sqLiteDatabase, int old, int newVersion) {
        Log.e("MySqLiteOpenHelper","onUpgrade");
        if (old == 1 && newVersion == 2){
            //对数据表进行升级
            String sql = "ALTER TABLE student ADD gender INT default 0";
            sqLiteDatabase.execSQL(sql);
        }
    }
}
